#include <QDataStream>
#include "sm-global.h"
#include "result-error.h"

QDataStream& operator<< (QDataStream& stream, const ResultError& error)
{
    stream << error.code() << error.text();
    return stream;
}

QDataStream& operator>> (QDataStream& stream, ResultError& error)
{
    if (stream.status() != QDataStream::Ok || stream.atEnd())
        return stream;

    int errorType;
    stream >> errorType;
    if (stream.status() != QDataStream::Ok || stream.atEnd())
        return stream;

    int errorCode;
    stream >> errorCode;
    if (stream.status() != QDataStream::Ok)
        return stream;

    QString errorText;
    stream >> errorText;
    if (stream.status() != QDataStream::Ok)
        return stream;

    error.setError(errorText, errorCode);
    return stream;
}
